package com.yrxy.thread.case7;

import java.util.concurrent.Callable;

/**
 * 奖品线程
 */
public class PrizeThread implements Callable<String> {
    Object prize = new Object();
    boolean flag = false;

    @Override
    public String call() throws Exception {
        Thread.sleep(1000);
        synchronized (prize) {

            if (flag == false) {
                // 第一个进来的人立马给标记位改成true了,然后别人再进来之后,发现是true就直接 就得到结果是 抽奖失败
                flag = true;
                return Thread.currentThread().getName() + "抽奖成功！";
            } else {
                return Thread.currentThread().getName() + "抽奖失败！";
            }
        }
    }


}
